﻿<base:IndexPanelBase x:Class="Rio.Framework.Pages.Controls.SearchPanel"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:base="clr-namespace:Rio.Framework.Pages.Controls.BaseClass"
                     xmlns:helpers="clr-namespace:Rio.Framework.Pages.AppCode.Helpers"
                     xmlns:controls="clr-namespace:Rio.Framework.Pages.Controls"
                     xmlns:criterias="clr-namespace:Rio.Framework.Pages.CriteriaControls"
                     xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                     xmlns:mvvmLightCommand="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
                     mc:Ignorable="d"
                     d:DesignHeight="700"
                     d:DesignWidth="300"
                     Loaded="UCSearchPanel_Loaded"
                     x:Name="UCSearchPanel">

    <base:IndexPanelBase.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Assets/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

        <controls:SearchPanelModeToIntConverter x:Name="SearchPanelModeToIntConverter" />
        <controls:NullToVisibilityConverter x:Name="NullToVisibilityConverter" />
        <controls:BoolToOppositeBoolConverter x:Name="BoolToOppositeBoolConverter" />
    </base:IndexPanelBase.Resources>

    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="SearchPanelStates">
                <VisualState x:Name="Default" />
                <VisualState x:Name="Minimized">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                       Storyboard.TargetName="clearButton">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                       Storyboard.TargetName="searchTextBlock">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)"
                                                       Storyboard.TargetName="radToolBar">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <HorizontalAlignment>Left</HorizontalAlignment>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadOutlookBar Name="radToolBar"
                               SelectedIndex="{Binding CurrentSearchPanelMode, ElementName=UCSearchPanel, Mode=TwoWay, Converter={StaticResource SearchPanelModeToIntConverter}}"
                               MinimizedButtonContent="{Binding SelectedItem.Header, ElementName=radOutlookBar, Mode=TwoWay}"
                               Template="{StaticResource RadOutlookBarControlTemplate}"
                               ActiveItemsMaxCount="3"
                               MinimizedWidth="44"
                               MinimizedWidthThreshold="44"
                               MinimizedAreaVisibility="Collapsed">
            <telerik:RadOutlookBarItem Name="foldersBarItem"
                                       Header="Dossiers"
                                       Style="{StaticResource RadOutlookBarItemStyle}"
                                       Icon="/Rio.Framework.Pages;component/Assets/Images/folder_search_big.png"
                                       SmallIcon="/Rio.Framework.Pages;component/Assets/Images/folder_search_small.png">
                <Grid Background="#FFEFEFEF">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <controls:UCOrganizationTypePanel x:Name="UCOrganizationType"
                                                      Mode="Search"
                                                      Margin="0,0,5,0"
                                                      SelectedOrganization="{Binding m_oCurrentOrganization, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                      SelectedFolderType="{Binding m_oCurrentFolderType, ElementName=UCSearchPanel, Mode=TwoWay}">
                        <i:Interaction.Behaviors>
                            <controls:LoadUcOrganizationTypePanelBehavior />
                        </i:Interaction.Behaviors>
                    </controls:UCOrganizationTypePanel>

                    <ScrollViewer Grid.Row="1"
                                  Background="White"
                                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                                  Visibility="{Binding m_oCurrentFolderType, ElementName=UCSearchPanel, Mode=TwoWay, Converter={StaticResource NullToVisibilityConverter}}">
                        <ContentControl>
                            <StackPanel HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch">

                                <criterias:StackIndexControl x:Name="foldersIndex"
                                                             IsSearchMode="True"
                                                             HorizontalAlignment="Stretch"
                                                             VerticalAlignment="Stretch" />

                                <Grid Margin="0,10,0,0">

                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60" />
                                        <ColumnDefinition Width="221" />
                                        <ColumnDefinition Width="11*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="20" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <RadioButton Name="foldersAndButton"
                                                 Content="Et"
                                                 Grid.Column="0"
                                                 Grid.Row="0"
                                                 IsChecked="{Binding FolderSearchRequest.UseAndOperator, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                 GroupName="FolderOperatorGroup"
                                                 HorizontalAlignment="Left" />
                                    <RadioButton Name="foldersOrButton"
                                                 Content="Ou"
                                                 Grid.Column="1"
                                                 Grid.Row="0"
                                                 IsChecked="false"
                                                 GroupName="FolderOperatorGroup" />
                                    <StackPanel Orientation="Horizontal"
                                                Grid.Row="1"
                                                Grid.ColumnSpan="3">
                                        <TextBlock Name="foldersFullTextLabel"
                                                   Text="Contenant (Recherche FullText)" />
                                        <Button Width="20"
                                                Height="20"
                                                Click="ButtonFullTextHelperClick"
                                                Background="{x:Null}"
                                                BorderBrush="{x:Null}"
                                                BorderThickness="0">
                                            <Image Source="/Rio.Framework.Pages;component/Assets/Images/Help.png"
                                                   Stretch="UniformToFill" />
                                        </Button>
                                    </StackPanel>
                                    <TextBox Grid.Row="2"
                                             Grid.ColumnSpan="3"
                                             VerticalContentAlignment="Stretch"
                                             Margin="5,10,5,5"
                                             Text="{Binding FolderSearchRequest.FullTextSearch, ElementName=UCSearchPanel, Mode=TwoWay}"
                                             helpers:BindingHelper.UpdateSourceOnChange="True" />
                                </Grid>

                            </StackPanel>
                        </ContentControl>
                    </ScrollViewer>
                    <CheckBox x:Name="saveSearchCheckBox"
                              Content="Sauvegarder les critères de cette recherche"
                              Margin="5"
                              Grid.Row="2"
                              IsEnabled="{Binding FolderSearchRequest.EnableSaveSearch, ElementName=UCSearchPanel, Mode=TwoWay}"
                              IsChecked="{Binding FolderSearchRequest.SaveSearch, ElementName=UCSearchPanel, Mode=TwoWay}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Checked">
                                <mvvmLightCommand:EventToCommand Command="{Binding SaveSearchCommand, ElementName=UCSearchPanel}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </CheckBox>

                </Grid>
            </telerik:RadOutlookBarItem>
            <telerik:RadOutlookBarItem Name="advancedFoldersbarItem"
                                       Header="Dossiers (avancée)"
                                       Style="{StaticResource RadOutlookBarItemStyle}"
                                       Icon="/Rio.Framework.Pages;component/Assets/Images/advanced_folder_search_big.png"
                                       SmallIcon="/Rio.Framework.Pages;component/Assets/Images/advanced_folder_search_small.png">
                <Grid Background="#FFEFEFEF">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <controls:UCOrganizationTypePanel Mode="Search"
                                                      SelectedOrganization="{Binding m_oCurrentOrganization, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                      SelectedFolderType="{Binding m_oCurrentFolderType, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                      Margin="0,0,5,0">
                        <i:Interaction.Behaviors>
                            <controls:LoadUcOrganizationTypePanelBehavior />
                        </i:Interaction.Behaviors>
                    </controls:UCOrganizationTypePanel>

                    <ScrollViewer Grid.Row="1"
                                  Background="White"
                                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                                  Visibility="{Binding m_oCurrentFolderType, ElementName=UCSearchPanel, Mode=TwoWay, Converter={StaticResource NullToVisibilityConverter}}">
                        <ContentControl>
                            <criterias:StackIndexSearch x:Name="advancedSearchIndex" />
                        </ContentControl>
                    </ScrollViewer>

                </Grid>
            </telerik:RadOutlookBarItem>
            <telerik:RadOutlookBarItem Name="documentsBarItem"
                                       Header="Documents"
                                       IsEnabled="{Binding IsImportSearch, ElementName=UCSearchPanel, Mode=TwoWay, Converter={StaticResource BoolToOppositeBoolConverter}}"
                                       Style="{StaticResource RadOutlookBarItemStyle}"
                                       Icon="/Rio.Framework.Pages;component/Assets/Images/document_search_big.png"
                                       SmallIcon="/Rio.Framework.Pages;component/Assets/Images/document_search_small.png">
                <Grid Background="#FFEFEFEF">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <controls:UCOrganizationTypePanel Mode="Search"
                                                      SelectedOrganization="{Binding m_oCurrentOrganization, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                      SelectedFolderType="{Binding m_oCurrentFolderType, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                      Margin="0,0,5,0">
                        <i:Interaction.Behaviors>
                            <controls:LoadUcOrganizationTypePanelBehavior />
                        </i:Interaction.Behaviors>
                    </controls:UCOrganizationTypePanel>

                    <ScrollViewer Grid.Row="1"
                                  Background="White"
                                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                                  Visibility="{Binding m_oCurrentFolderType, ElementName=UCSearchPanel, Mode=TwoWay, Converter={StaticResource NullToVisibilityConverter}}">
                        <ContentControl>
                            <StackPanel HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch">

                                <criterias:StackIndexControl x:Name="documentsIndex"
                                                             IsSearchMode="True"
                                                             HorizontalAlignment="Stretch"
                                                             VerticalAlignment="Stretch" />

                                <Grid Margin="0,10,0,0">

                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60" />
                                        <ColumnDefinition Width="221" />
                                        <ColumnDefinition Width="11*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="20" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <RadioButton Name="documentsAndButton"
                                                 Content="Et"
                                                 Grid.Column="0"
                                                 Grid.Row="0"
                                                 IsChecked="{Binding DocumentSearchRequest.UseAndOperator, ElementName=UCSearchPanel, Mode=TwoWay}"
                                                 GroupName="DocumentOperatorGroup"
                                                 HorizontalAlignment="Left" />
                                    <RadioButton Name="documentsOrButton"
                                                 Content="Ou"
                                                 Grid.Column="1"
                                                 Grid.Row="0"
                                                 IsChecked="false"
                                                 GroupName="DocumentOperatorGroup" />
                                    <StackPanel Orientation="Horizontal"
                                                Grid.Row="1"
                                                Grid.ColumnSpan="3">
                                        <TextBlock Name="documentsFullTextLabel"
                                                   Text="Contenant (Recherche FullText)" />
                                        <Button Width="20"
                                                Height="20"
                                                Click="ButtonFullTextHelperClick"
                                                Background="{x:Null}"
                                                BorderBrush="{x:Null}"
                                                BorderThickness="0">
                                            <Image Source="/Rio.Framework.Pages;component/Assets/Images/Help.png"
                                                   Stretch="UniformToFill" />
                                        </Button>
                                    </StackPanel>
                                    <TextBox Grid.Row="2"
                                             Grid.ColumnSpan="3"
                                             VerticalContentAlignment="Stretch"
                                             Text="{Binding DocumentSearchRequest.FullTextSearch, ElementName=UCSearchPanel, Mode=TwoWay}"
                                             Margin="5,10,5,5"
                                             helpers:BindingHelper.UpdateSourceOnChange="True" />

                                </Grid>
                            </StackPanel>
                        </ContentControl>
                    </ScrollViewer>

                </Grid>
            </telerik:RadOutlookBarItem>
        </telerik:RadOutlookBar>
        <telerik:RadToolBar Grid.Row="1"
                            telerik:StyleManager.Theme="OfficeBlack"
                            Height="30"
                            OverflowButtonVisibility="Collapsed"
                            GripVisibility="Collapsed">
            <telerik:RadButton Margin="2,0,2,0"
                               Name="clearButton"
                               Command="{Binding ClearCriteriasCommand, ElementName=UCSearchPanel, Mode=TwoWay}">
                <StackPanel Orientation="Horizontal">
                    <Image Width="16"
                           Height="16"
                           Margin="0,0,2,0"
                           Source="/Rio.Framework.Pages;component/Assets/Images/Clear.png" />
                    <TextBlock Name="clearButtonLabel"
                               VerticalAlignment="Center"
                               Text="Effacer" />
                </StackPanel>
            </telerik:RadButton>
            <telerik:RadButton Margin="2,0,2,0"
                               Name="searchButton"
                               Command="{Binding SearchCommand, ElementName=UCSearchPanel, Mode=TwoWay}">
                <StackPanel Orientation="Horizontal">
                    <Image Width="16"
                           Height="16"
                           Margin="0,0,2,0"
                           Source="/Rio.Framework.Pages;component/Assets/Images/SearchBinoculars.png" />
                    <TextBlock Name="searchTextBlock"
                               VerticalAlignment="Center"
                               Text="Rechercher" />
                </StackPanel>
            </telerik:RadButton>
        </telerik:RadToolBar>
    </Grid>

</base:IndexPanelBase>
